1492B - Card Deck - CodeForces Solution


data structures greedy math *1100

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<cmath>
using namespace std;
typedef long long ll;
#define loop(n) for(ll i=0 ; i<n ; i++)
#define loop2(n) for(ll j=0 ; j<n ; j++)

#define fr(i,n)           for (ll i=0;i<n;i++)
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int fib(int n)
{
    if(n <= 1)
        return n;

    return fib(n-1) + fib(n-2);
}
long long Fib[]= {0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987,
                  1597, 2584, 4181, 6765,  10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811,
                  514229, 832040, 1346269, 2178309, 3524578,  5702887, 9227465, 14930352, 24157817,
                  39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733,
                  1134903170, 1836311903
                 };
int gcd(int a, int b)
{
    if(b==0)
        return a;
    return gcd(b, a%b);
}
struct student
{
    string name;
    int grade1,grade2,grade3,grade4;
    int sum;
    bool operator <(const student s1)
    {
        if(abs(sum-s1.sum)>10)
            return sum>s1.sum;
        else
            return name<s1.name;
    }

};
/*double binary_searchh(double low,double high,double key)
{
    double mid;
    for(double i=low; i<maxx; i++)
    {
        mid=(high+low)/2;
        double res=(double)mid*log2(mid);
       // cout<<" mid "<<mid<<" res "<<res<<" ";
        if(res==key)
        {
            return mid;
        }
        else  if(res<key)
        {
            low=mid;
           // cout<<" low  "<<low<<endl;
        }
        else
        {
            high=mid;
            //cout<<" high  "<<high<<endl;
        }
    }
*/
int main()
{
    fast();
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        vector<ll> v(100003),p(100003);
        for(int i=1; i<=n; i++){
            cin>>v[i];
            p[v[i]]=i;
        }
         int x=n+1;
            for(int i=n; i>0; i--)
            {
                if(p[i]<x)
                {
                    for(int j=p[i];j<x;j++)
                    {
                        cout<<v[j]<<" ";
                        //x=p[i];
                    }
                    x=p[i];
                }
            }
            cout<<endl;
        }




    return 0;

}


Comments

Submit
0 Comments
More Questions

328. Odd Even Linked List
1219. Path with Maximum Gold
1268. Search Suggestions System
841. Keys and Rooms
152. Maximum Product Subarray
337. House Robber III
869. Reordered Power of 2
1593C - Save More Mice
1217. Minimum Cost to Move Chips to The Same Position
347. Top K Frequent Elements
1503. Last Moment Before All Ants Fall Out of a Plank
430. Flatten a Multilevel Doubly Linked List
1290. Convert Binary Number in a Linked List to Integer
1525. Number of Good Ways to Split a String
72. Edit Distance
563. Binary Tree Tilt
1306. Jump Game III
236. Lowest Common Ancestor of a Binary Tree
790. Domino and Tromino Tiling
878. Nth Magical Number
2099. Find Subsequence of Length K With the Largest Sum
1608A - Find Array
416. Partition Equal Subset Sum
1446. Consecutive Characters
1618A - Polycarp and Sums of Subsequences
1618B - Missing Bigram
938. Range Sum of BST
147. Insertion Sort List
310. Minimum Height Trees
2110. Number of Smooth Descent Periods of a Stock